package com.qezhhnjy.demo.security.service;

import com.qezhhnjy.demo.security.dao.UserDao;
import com.qezhhnjy.demo.security.entity.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author zhaoyangfu
 * @date 2021/6/22-9:40
 */
@Service
public class UserService implements UserDetailsService {

    @Resource
    private UserDao userDao;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userDao.findUserByUsername(username);
        if (user == null) throw new UsernameNotFoundException("用户不存在");
        return user;
    }
}
